<!DOCTYPE html>
<html>
    <head>
        <!-- 当前文档的字符集编码为utf-8 -->
        <meta charset="utf-8">
        <meta name="author" content="disenQF" >
        <meta name="keywords" content="CGI开发 H5模板 千锋教育 西安物联网">
        <title>HTML5模板-window对象</title>
        <!-- 引入外联样式文件 -->
        <link rel="stylesheet" href="/css/my.css">
        <style>
         
        </style>
    </head>
    <body>
       <div id="d1">1</div>
       <div class="item">2</div>
       <div class="item">3</div>

       <script>
          let log = console.log;
          // 依据id查找标签对象
          let div1 = document.getElementById("d1");
         log(div1)

         // 查找2，3的div
         let divs = document.getElementsByClassName("item");
         log(divs);
         let names = ["李向前", "王红"];
         for(let i=0;i<divs.length;i++){
             let div = divs[i];
             div.innerHTML = names[i];
         }

         // 为每一个div添加一个点击事件的处理函数, 处理函数的功能：弹出对话框显示标签的内容
         let alldiv = document.getElementsByTagName("div"); 
         log(alldiv);
         for(let i =0;i<alldiv.length;i++){
            let _div = alldiv[i];
            _div.onclick = function(){
               alert(this.innerText);
            }
         }
       </script>
    </body>
</html>
